package com.ruoyi.web.controller.basedata;

import java.util.Date;
import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.basedata.domain.vo.UserTerminalsxbJoinBo;
import com.ruoyi.datastatistics.domain.PublicShareUserJoin;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.basedata.domain.UserTerminalsxbJoin;
import com.ruoyi.basedata.service.IUserTerminalsxbJoinService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 用户配置Controller
 *
 * @author gdqt
 * @date 2025-07-09
 */
@RestController
@RequestMapping("/basedata/userTerminalsxbJoin")
public class UserTerminalsxbJoinController extends BaseController
{
    @Autowired
    private IUserTerminalsxbJoinService userTerminalsxbJoinService;

    /**
     * 查询用户配置列表
     */
    @PreAuthorize("@ss.hasPermi('basedata:join:list')")
    @GetMapping("/list")
    public TableDataInfo list(UserTerminalsxbJoin userTerminalsxbJoin)
    {
        startPage();
        List<UserTerminalsxbJoin> list = userTerminalsxbJoinService.selectUserTerminalsxbJoinList(userTerminalsxbJoin);
        return getDataTable(list);
    }

    @PreAuthorize("@ss.hasPermi('basedata:join:list')")
    @GetMapping("/listMore")
    public TableDataInfo listMore(UserTerminalsxbJoin userTerminalsxbJoin)
    {
        // startPage();
        List<UserTerminalsxbJoinBo> list = userTerminalsxbJoinService.selectUserTerminalsxbJoinListMore(userTerminalsxbJoin);
        return getDataTable(list);
    }



    /**
     * 导出用户配置列表
     */
    @PreAuthorize("@ss.hasPermi('basedata:join:export')")
    @Log(title = "用户配置", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, UserTerminalsxbJoin userTerminalsxbJoin)
    {
        List<UserTerminalsxbJoin> list = userTerminalsxbJoinService.selectUserTerminalsxbJoinList(userTerminalsxbJoin);
        ExcelUtil<UserTerminalsxbJoin> util = new ExcelUtil<UserTerminalsxbJoin>(UserTerminalsxbJoin.class);
        util.exportExcel(response, list, "用户配置数据");
    }

    /**
     * 获取用户配置详细信息
     */
    @PreAuthorize("@ss.hasPermi('basedata:join:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(userTerminalsxbJoinService.selectUserTerminalsxbJoinById(id));
    }

    /**
     * 新增用户配置
     */
    @PreAuthorize("@ss.hasPermi('basedata:join:add')")
    @Log(title = "用户配置", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody UserTerminalsxbJoin userTerminalsxbJoin)
    {
        return toAjax(userTerminalsxbJoinService.insertUserTerminalsxbJoin(userTerminalsxbJoin));
    }

    /**
     * 批量新增区域绑定设备
     */
    @Log(title = "挂接设备", businessType = BusinessType.INSERT)
    @PostMapping("/adduserTerminalsxbJoinList")
    public AjaxResult adduserTerminalsxbJoinList(@RequestBody List<UserTerminalsxbJoin> list) {
        String tenantId = getLoginUser().getTenantId();
        if(!list.isEmpty()){
            list.forEach(e -> {
                e.setTenantId(tenantId);
                e.setUpdateTime(new Date());
            });
            userTerminalsxbJoinService.saveBatch(list);
        }
        return success("新增成功");
    }



    /**
     * 修改用户配置
     */
    @PreAuthorize("@ss.hasPermi('basedata:join:edit')")
    @Log(title = "用户配置", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody UserTerminalsxbJoin userTerminalsxbJoin)
    {
        userTerminalsxbJoin.setUpdateTime(new Date());
        return toAjax(userTerminalsxbJoinService.updateUserTerminalsxbJoin(userTerminalsxbJoin));
    }

    /**
     * 删除用户配置
     */
    @PreAuthorize("@ss.hasPermi('basedata:join:remove')")
    @Log(title = "用户配置", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(userTerminalsxbJoinService.deleteUserTerminalsxbJoinByIds(ids));
    }
}
